package com.tms.basic.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tms.basic.pojo.domain.Department;
import com.tms.basic.service.DepartmentService;
import com.tms.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/department")
public class DepartmentController {
    
    @Autowired
    private DepartmentService departmentService;
    
    @PostMapping("/listDepartment")
    public R<Page<Department>> listDepartment(Page<Department> page, Department department) {
        return R.success(departmentService.listDepartments(page, department));
    }
    
    @PostMapping("/addDepartment")
    public R<Boolean> addDepartment(@RequestBody Department department) {
        return R.success(departmentService.createDepartment(department));
    }
    
    @PostMapping("/updateDepartment")
    public R<Boolean> updateDepartment(@RequestBody Department department) {
        return R.success(departmentService.updateDepartment(department));
    }
    
    @PostMapping("/deleteDepartment/{id}")
    public R<Boolean> deleteDepartment(@PathVariable Long id) {
        return R.success(departmentService.deleteDepartment(id));
    }
}